<template>
	<view class="home">
		<swiper indicator-dots circular autoplay="true">
			<swiper-item v-for="item in swipers" :key="item.id">
				<image :src="item.img"></image>
			</swiper-item>
		</swiper>

		<!-- 导航区域 -->
		<view class="nav">
			<view class="nav_item" v-for="(item,index) in navs" :key="index" @click="navItemClick(item.path)">
				<view :class="item.icon"></view>
				<text>{{item.title}}</text>
			</view>
		</view>

		<!-- 推荐商品区 -->
		<view class="hot_goods">
			<view class="tit">推荐视频</view>
			<goods-list :hotgoods="hotgoods"></goods-list>

			<view class="tit">推荐漫展</view>
			<view class="goods_list">
				<view class="goods_item" v-for="(sp,index) in shops" :key="index">
					<image :src="sp.img_url"></image>
					<view class="price">
						<text>￥{{sp.sell_price}}</text>
						<text>{{sp.market_price}}</text>
					</view>
					<view class="name">
						{{sp.title}}
					</view>
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	import goodsList from '../../components/goods-list/goods-list.vue'

	export default {
		data() {
			return {
				swipers: [],
				hotgoods: '',
				navs: [{
						icon: 'iconfont icon-ziyuan',
						title: '番剧列表',
						path: '../goods/goods'
					},
					{
						icon: 'iconfont icon-guanyuwomen',
						title: '联系我们',
						path: '../contact/contact'
					},
					{
						icon: 'iconfont icon-shipin',
						title: '视频分类',
						path: '../pics/pics'
					},
					{
						icon: 'iconfont icon-tupian ',
						title: '社区图片',
						path: '../videos/videos'
					}
				],
				shops: []
			}
		},
		onLoad() {
			this.getSwipers()
			this.getHotGoods()
			this.getshop()
		},
		methods: {
			// 获取轮播图的数据
			getSwipers() {
				uni.request({
					url: "http://127.0.0.1:5500/api/shop/lunbotu.json",
					success: (res) => {
						if (res.data.status != 0) {
							return uni.showToast({
								title: '获取数据失败'
							})
						} else {
							this.swipers = res.data.message
						}
					}
				})
			},
			// 获取热门商品列表数据
			getHotGoods() {
				uni.request({
					url: 'http://127.0.0.1:5500/api/shop/HotGoods.json?pageindex=1',
					success: res => {
						this.hotgoods = res.data.message
					}
				})
			},
			// 获取周边商品
			getshop() {
				uni.request({
					url: 'http://127.0.0.1:5500/api/shop/shangpin.json',
					success: res => {
						console.log(res);
						this.shops = res.data.message
					}
				})
			},
			// 导航点击
			navItemClick(u) {
				uni.navigateTo({
					url: u
				})
			}
		},
		components: {
			"goods-list": goodsList
		}
	}
</script>

<style lang=scss>
	.home {
		swiper {
			width: 750rpx;
			height: 380rpx;

			image {
				width: 100%;
				height: 100%;
			}
		}
	}

	.nav {
		display: flex;
		margin: 10rpx 0 0 0;

		.nav_item {
			width: 25%;
			text-align: center;

			view {
				width: 95rpx;
				height: 95rpx;
				border-radius: 60rpx;
				background: $shop-color;
				margin: 10rpx auto;
				line-height: 95rpx;
				color: #fff;
				font-size: 50rpx;
			}

			.icon-tupian {
				font-size: 45rpx;
			}

			text {
				font-size: 30rpx;
			}
		}
	}

	.hot_goods {
		background: #eee;
		overflow: hidden;
		margin-top: 10px;
		border-radius: 20rpx;

		.tit {
			height: 50px;
			line-height: 50px;
			color: $shop-color;
			text-align: center;
			letter-spacing: 20px;
			background: #fff;
			border-radius: 20rpx;
			margin: 7px 0;
		}
		.goods_list {
			padding: 0 15rpx;
			display: flex;
			flex-wrap: wrap;
			justify-content: span-between;
		
			.goods_item {
				background: #fff;
				width: 355rpx;
				margin: 6rpx 3rpx;
				padding: 15rpx;
				box-sizing: border-box;
				border-radius: 20rpx;
		
				image {
					width: 80%;
					height: 150px;
					display: block;
					margin: 0 auto;
				}
		
				.price {
					color: $shop-color;
					font-size: 35rpx;
					text:nth-child(1){
						display: block;
						margin-top: 20rpx;
					}
					text:nth-child(2) {
						display: block;
						color: #999;
						margin-left: 10rpx;
						font-size: 28rpx;
						
					}
				}
				
				.name {
					font-size: 28rpx;
					line-height: 50rpx;
					padding: 10rpx 0 15rpx 0;
				}
			}
		}
	}
</style>
